const { validationResult } = require('express-validator');
const ApiError = require('./utils/api_error');

function express_validate(req, res, next) {
    const errors = validationResult(req);
    if (!errors.isEmpty()) {
        const msg = errors.array().map(e => `${e.type}: ${e.msg}`).join('; ');
        return next(ApiError.BadRequest(msg));
    }
    next();
}

module.exports = express_validate

